package app.mvp.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

import app.mvp.R;

/**
 * Created by 刘智强 on 2017/5/27.
 */

public class PhotoAdapter extends RecyclerView.Adapter<PhotoAdapter.MyViewHolder> {
    private Context context;
    private List<Bitmap> bitmapList;

    public PhotoAdapter(Context context, List<Bitmap> bitmapList) {
        this.context = context;
        this.bitmapList = bitmapList;
    }

    @Override
    public PhotoAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_photo_adapter,parent,false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (!bitmapList.isEmpty()){
            holder.iv_photo.setImageBitmap(bitmapList.get(position));
        }

    }

    @Override
    public int getItemCount() {
        return bitmapList.isEmpty()?0:bitmapList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_photo;

        public MyViewHolder(View itemView) {
            super(itemView);
            iv_photo = (ImageView) itemView.findViewById(R.id.iv_photo);
        }
    }
}
